//#include "../head.h"
#include <atomic>
#include <vector>
#include <string>
#include <assert.h>
#include <string>
#include <string.h>

#include <unistd.h>
#include <sys/types.h>
#include <sys/uio.h>
#ifndef BUFF_H_
#define BUFF_H_ 1

namespace Buffer_
{
class Buffer
{
public:
    Buffer(int initBufferSize = 1024);

    size_t writeToFd(int fd,int *Errnoo);
    size_t readFromdFd(int fd,int *Errnoo);    

    void append(const char *str,size_t size);
    void append(const std::string& str);
    void append(void *str,size_t size);
    void append(const Buffer& Buffer_);
    void isEnableWrite(size_t size);
    void makezero();
    void HasWriten(size_t len);
    void HasRead(size_t len);

    size_t prependableBytes() const;
    size_t readableBytes() const;
    size_t writeableBytes() const;

    const char *RIndex_cptr() const;
    const char *WIndex_cptr() const;
    char *RIndex_ptr();
    char *WIndex_ptr();
    const char *Begin_cptr();
    char *Begin_ptr();

    std::string getReadBlock();
    /*size_t size()
    {
        return buffer_.size();
    }
    size_t capacity()
    {
        return buffer_.capacity();
    }*/

private:
    std::vector<char> buffer_;
    std::atomic<int> Index_read;
    std::atomic<int> Index_write;
    void Rmove_RW_Index(std::atomic<int>& Index,size_t len);    //right move

    void move_block(size_t size);
};
}//namespace Buffer
#endif